package com.sbl.controller;

import com.sbl.domain.Account;
import com.sbl.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *      请求参数获取
 */
@Controller
@RequestMapping("/params")
public class ParamsController {


    /**
     *  请求参数入门
     * @param userName  ：这个变量的名字必须和请求的  Key一致
     * @return
     */
    @RequestMapping("/testparam")
    public String testParams(String userName){
        System.out.println("testParams 方法请求到了");
        System.out.println("参数名字是" +userName);
        return "success";
    }


    /**
     *  请求接收   JavaBean
     * @param account：这个变量的名字必须和请求的  Key一致
     * @return
     */
    @RequestMapping(value = "/testJavaBeanParams",method = RequestMethod.POST)
    public String testJavaBeanParams(Account account){
        System.out.println("testJavaBeanParams 方法请求到JavaBean");
        System.out.println("接收到的JavaBean是：" +account.toString());
        return "success";
    }


    /**
     *  自定义类型转换器
     * @param user：这个变量的名字必须和请求的  Key一致
     * @return
     */
    @RequestMapping(value = "/saveuser",method = RequestMethod.POST)
    public String saveUser(User user){
        System.out.println("saveUser 方法请求到");
        System.out.println("接收到的需要转换的实体是user：" +user.toString());
        return "success";
    }

    /**
     *   在框架内获取原生的  ServletRequest ，ServletResponse
     */
    @RequestMapping(value = "/testServlet",method = RequestMethod.GET)
    public String testServlet(HttpServletRequest request, HttpServletResponse response){
        System.out.println("testServlet 方法请求到");
        System.out.println("获取到原生的HttpServletRequest：" +request.getSession());
        return "success";
    }
}
